package com.itbaima.csmall.stock.webapi.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>库存数据访问层</p>
 *
 * @author Chen
 * @since 2023/2/20 14:27:27
 */
@Mapper
public interface StockMapper {

    /**
     * 修改/减少指定商品库存数
     *
     * @param commodityCode 商品编码
     * @param reduceCount   减少的数量
     * @return 受影响的行
     */
    @Update("UPDATE stock_tbl SET count = count - #{reduceCount} " +
            "WHERE commodity_code = #{commodityCode} AND count >= #{reduceCount}")
    int updateStockCountByCommodityCode(@Param("commodityCode") String commodityCode,
                                        @Param("reduceCount") Integer reduceCount);

}
